package com.magic.gre.mvp.presenter;

import com.google.gson.reflect.TypeToken;
import com.magic.gre.entity.WordsBean;
import com.magic.gre.entity.base.BaseListModel;
import com.magic.gre.entity.base.BaseObjectModel;
import com.magic.gre.mvp.contract.RipeWordsContract;
import com.magic.gre.mvp.model.RipeWordsModelImpl;
import com.noname.lib_base_java.mvp.BasePresenterImpl;

/**
 * Author: Lmoumou
 * Date: 2019-01-07 18:26
 * 文件名: RipeWordsPresenterImpl
 * 描述:
 */
public class RipeWordsPresenterImpl extends BasePresenterImpl<RipeWordsContract.View, RipeWordsContract.Model>
        implements RipeWordsContract.Presenter {
    public RipeWordsPresenterImpl(RipeWordsContract.View view) {
        super(view);
    }

    @Override
    protected RipeWordsContract.Model creatModel() {
        return new RipeWordsModelImpl();
    }

    @Override
    public void pRipeWordsList(int pageNo) {
        mModel.mRipeWordsList(new CommonObserver<BaseListModel<WordsBean>>(new TypeToken<BaseListModel<WordsBean>>(){}.getType()) {
            @Override
            protected void onSuccess(BaseListModel<WordsBean> wordsBeanBaseListModel) {
                mView.vRipeWordsList(wordsBeanBaseListModel.body);
            }

            @Override
            public void onError(int status, String msg) {

            }
        }, pageNo);
    }

    @Override
    public void pRipeDelete(String ids) {
        mModel.mRipeDelete(new CommonObserver<BaseObjectModel>(new TypeToken<BaseObjectModel>(){}.getType()) {
            @Override
            protected void onSuccess(BaseObjectModel baseObjectModel) {
                mView.vRipeDelete();
            }

            @Override
            public void onError(int status, String msg) {
                mView.doPrompt(msg);
            }
        }, ids);
    }
}
